import React, { Component } from "react";
import { Toast, Modal } from "antd-mobile";
import "./activeSuccess.scss";
import { connect } from "react-redux";
import XFButton from "../../../xfCompontent/xfButton/xfButton";
import yhTools from "../../../tools/yh";
import sumitSuccess from "../../../images/imageXHF/paySuccess.png";
import { InterfaceG } from "../../../config/Config";
import MainLayout from "../../../component/mainLayout/mainLayout";
import { getAppPlatformsDatas } from "../../../Redux/Action/nativeDatas/nativeDatas";
const alert = Modal.alert;
export class activeSuccess extends Component {
	constructor(props) {
		super(props);
		this.state = {
			btnText: "返回首页",
			isShowModal: false,
			backPath: "/xhfHomeCredit"
		};
	}

	componentDidMount() {}
	btnFn(e) {
		if (e == "1") {
			this.props.history.replace("/xhfHomeCredit");
		} else if (e == "2") {
			this.goPaymentCode();
		}
	}
	//小辉付跳转不同首页
	jumpPage(url, Urlparams) {
		this.props.history.push({
			pathname: `/${url}`,
			state: Urlparams
		});
	}
	// 去付款码
	goPaymentCode() {
		let objs = {
			url: InterfaceG.appBtnPaymentCode,
			params: {
				version: "1.0"
			}
		};
		Toast.loading("加载中...", 100);
		const _this = this;
		yhTools.request(objs).then(res => {
			Toast.hide();
			if (res.code === "0") {
				const pageNo = res.data.pageNo;
				const pageName = res.data.pageName;
				switch (pageNo) {
					case "7": // 7 付款码
						_this.jumpPage("payCode");
						break;
					case "8": //8 设置支付密码
						_this.props.history.push({
							pathname: "/xhfSetPasswordPage",
							state: {
								gotoNext: "edjh"
							}
						});
						break;
					case "13": //逾期情况
						alert("", pageName, [
							{
								text: "去还款",
								onPress: () => {
									_this.jumpPage("billHome");
								}
							}
						]);
						break;
					case "14": //额度不足
						Toast.info(pageName, 2);
						break;
					case "15": //激活页面
						_this.jumpPage("xhfFacilitySuccess");
						break;
					default:
						break;
				}
			} else {
				Toast.info(res.message, 2);
			}
		});
	}
	render() {
		let _pageParams = {
			header: {
				title: "激活成功",
				goBackPath: this.state.backPath
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		const btnStyle = {
			height: "0.90rem",
			width: "3rem",
			borderRadius: ".50rem",
			fontSize: ".32rem"
		};
		const btnStyle1 = {
			height: "0.90rem",
			width: "3rem",
			borderRadius: ".50rem",
			background: "white",
			border: "1px solid rgba(248,38,45,1)",
			color: "#F82633",
			fontSize: ".32rem"
		};
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="activeSuccess">
					<div className="activeSuccess-box">
						<img src={sumitSuccess} />
						<h3>激活成功</h3>
					</div>
					<div className="btn-con">
						<XFButton
							btText={"查看我的小辉付"}
							btnStyle={btnStyle1}
							handleBtn={this.btnFn.bind(this, 1)}
						/>
						<XFButton
							btText={"立即使用"}
							btnStyle={btnStyle}
							handleBtn={this.btnFn.bind(this, 2)}
						/>
					</div>
				</div>
			</MainLayout>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps(dispatch) {
	return {
		_getAppPlatformsDatas: abj => {
			//获取native的数据
			dispatch(getAppPlatformsDatas(abj));
		}
	};
}

const OpenSuccessPage = connect(
	mapStateToProps,
	mapDispatchToProps
)(activeSuccess);
export default OpenSuccessPage;
